home *** CD-ROM | disk | FTP | other *** search
/ The Guided Tour of Multimedia (Second Edition) / The Guided Tour of Multimedia (Second Edition).iso / trials / qtw111 / samples / common.cpp < prev    next >
C/C++ Source or Header  |  1994-01-11  |  6KB  |  191 lines

  1.  
  2. // ---------------------------------------------------------------------
  3. //
  4. // COMMON.CPP   - QuickTime for Windows Sample Decompressor
  5. //
  6. //                Version 1.1
  7. //
  8. //                (c) 1988-1993 Apple Computer, Inc. All Rights Reserved.
  9. //
  10. // ---------------------------------------------------------------------
  11.  
  12.  
  13. // Windows header files
  14. #include <windows.h>
  15. #include <windowsx.h>
  16.  
  17. // Compiler header files
  18. #include <ver.h>
  19.  
  20. // Application header files
  21. #include "prototyp.hp"
  22.  
  23. // Local functions
  24. static VOID FAR PASCAL FixupCM( ENTRYFUNC lpfnCM) ;
  25. static VOID FAR PASCAL FixupTB( ENTRYFUNC lpfnTB) ;
  26.  
  27. // Global data
  28. ENTRYFUNC lpfnQTComponentManager ;
  29. ENTRYFUNC lpfnQTToolbox ;
  30. extern "C" BOOL fQTInitPerformed ;
  31. extern ComponentDescription cdTable[] ; // components in this DLL
  32.  
  33. /* function cfCanDoSelect:
  34.    Report if a function is implemented
  35. */
  36. ComponentResult QTAPI cfCanDoSelect( STKOFF_CMP so, LONG lFunctionSelector)
  37. {
  38.     switch ( lFunctionSelector)  { // switch on function selector
  39.         case kComponentOpenSelect :
  40.         case kComponentCloseSelect :
  41.         case kComponentCanDoSelect :
  42.         case kComponentVersionSelect :
  43.         case kComponentRegisterSelect :
  44.         case kComponentTargetSelect :
  45.         case codecPreDecompress :
  46.         case codecBandDecompress :
  47.         case codecCDSequenceBusy :
  48.         case codecGetCodecInfo :
  49.             return TRUE ;
  50.         default :
  51.             return FALSE ;
  52.     } // switch on function selector
  53. } // cfCanDoSelect
  54.  
  55. /* function RegisterSelect:
  56.    Return 0 as there is nothing to check before registering
  57. */
  58. ComponentResult QTAPI cfRegisterSelect( STKOFF_CMP so, ComponentInstance ci)
  59. {
  60.     return 0;
  61. } // cfRegisterSelect
  62.  
  63. /* function TargetSelect:
  64.    Not implemented
  65. */
  66. ComponentResult QTAPI cfTargetSelect( STKOFF_CMP so, ComponentInstance ci)
  67. {
  68.     // successful return
  69.     return noErr ;
  70. } // cfTargetSelect
  71.  
  72. /* function cfVersionSelect:
  73.    Return the version of this component.  We take the information directly
  74.    the Windows version information.
  75. */
  76. ComponentResult QTAPI cfVersionSelect( STKOFF_CMP so, ComponentInstance ci)
  77. {
  78.     // load VER.DLL
  79.     UINT uOldErrorMode = SetErrorMode( SEM_NOOPENFILEERRORBOX) ; // no message box
  80.     HINSTANCE hLibrary = LoadLibrary( "ver.dll") ;
  81.     SetErrorMode( uOldErrorMode) ;                               // restore application's settings
  82.     if ( hLibrary < HINSTANCE_ERROR)                             // if load error
  83.         return -1 ;                                              // take error return
  84.  
  85.     // locate the exported functions of interest
  86.     typedef DWORD (WINAPI *PGETFILEVERSIONINFOSIZE) (LPCSTR, DWORD FAR *) ;
  87.     typedef BOOL (WINAPI *PGETFILEVERSIONINFO) (LPCSTR, DWORD, DWORD, LPVOID) ;
  88.     typedef BOOL ( WINAPI *PVERQUERYVALUE) ( const VOID FAR *
  89.                                            , LPCSTR
  90.                                            , VOID FAR * FAR *
  91.                                            , UINT FAR *
  92.                                            ) ;
  93.     PGETFILEVERSIONINFOSIZE pGetFileVersionInfoSize
  94.         = ( PGETFILEVERSIONINFOSIZE) GetProcAddress( hLibrary, "#6") ;
  95.     PGETFILEVERSIONINFO pGetFileVersionInfo
  96.         = ( PGETFILEVERSIONINFO) GetProcAddress( hLibrary, "#7") ;
  97.     PVERQUERYVALUE pVerQueryValue
  98.         = ( PVERQUERYVALUE) GetProcAddress( hLibrary, "#11") ;
  99.     if ( pGetFileVersionInfoSize == 0
  100.         ||  pGetFileVersionInfo == 0
  101.         ||  pVerQueryValue == 0)  {
  102.         FreeLibrary( hLibrary) ; // clean up
  103.         return -1 ;              // take error return
  104.     } // if any GetProcAddress call failed
  105.  
  106.     // get this module's file name
  107.     char szFilename[ _MAX_PATH] ;
  108.     if ( GetModuleFileName( GetInstOfThisMod()
  109.         , szFilename
  110.         , sizeof szFilename
  111.         ) == 0)  {
  112.         FreeLibrary( hLibrary) ; // clean up
  113.         return -1 ;              // take error return
  114.     } // if GetModuleFileName failed
  115.  
  116.     // get version data
  117.     DWORD hVer
  118.         , dwSize = ( *pGetFileVersionInfoSize)( szFilename, &hVer)
  119.         ;
  120.     if ( dwSize == 0)  {         // if error
  121.         FreeLibrary( hLibrary) ; // clean up
  122.         return -1 ;              // take error return
  123.     } // if error from GetFileVersionInfoSize
  124.     BYTE abData[ 512] ;
  125.     if ( ( *pGetFileVersionInfo)( szFilename, hVer, dwSize, abData) == FALSE)  {
  126.         FreeLibrary( hLibrary) ; // clean up
  127.         return -1 ;              // take error return
  128.     } // if error from GetFileVersionInfo
  129.     UINT uiSize ;
  130.     VS_FIXEDFILEINFO FAR *lpvsffi ;
  131.     if ( ( *pVerQueryValue) ( abData
  132.         , "\\"
  133.         , ( VOID FAR * FAR *) &lpvsffi
  134.         , &uiSize
  135.         ) == FALSE)  {           // if error
  136.         FreeLibrary( hLibrary) ; // clean up
  137.         return -1 ;              // take error return
  138.     } // if error from VerQueryValue
  139.     LONG lVersion = ( HIWORD( lpvsffi->dwProductVersionMS) << 4)
  140.         +  ( LOWORD( lpvsffi->dwProductVersionMS) << 8)
  141.         +  HIWORD( lpvsffi->dwProductVersionLS)
  142.         ;
  143.  
  144.     // clean up and return version number to caller
  145.     FreeLibrary( hLibrary) ;
  146.     return lVersion ;
  147. } // cfVersionSelect
  148.  
  149. /* function FixupCM:
  150.    Establish direct linkage to Component Manager
  151. */
  152. static VOID FAR PASCAL FixupCM( ENTRYFUNC lpfnCM)
  153. {
  154.     lpfnQTComponentManager = lpfnCM;
  155.     //fQTInitPerformed = TRUE;
  156. } // FixupCM
  157.  
  158. /* function FixupTB:
  159.    Establish direct linkage to Movie Toolbox
  160. */
  161. static VOID FAR PASCAL FixupTB( ENTRYFUNC lpfnTB)
  162. {
  163.     lpfnQTToolbox = lpfnTB;
  164.     //fQTInitPerformed = TRUE;
  165. } // FixupTB
  166.  
  167. /* function THNGIDENTIFY:
  168.    Entry point called by Component Manager
  169.  
  170.    The function fills the Component ID structure.
  171. */
  172. OSType FAR PASCAL THNGIDENTIFY( LPCID FAR *lplpcid)
  173. {
  174.     // allocate memory for CID information
  175.     // The memory will be freed by the Component Manager.
  176.     LPCID lpcid = ( LPCID) GetMemory( sizeof CID) ;
  177.     if ( lpcid == 0) // if allocation failed
  178.         return 0 ;   // take error return
  179.  
  180.     // fill the structure
  181.     lpcid->lVersion = CID_VERSION ;
  182.     lpcid->sComponentCount = 1 ;
  183.     lpcid->lpcdTable = ( LPCD) &cdTable ;
  184.     lpcid->lpfnTBFixup = FixupTB ;
  185.     lpcid->lpfnCMFixup = FixupCM ;
  186.     *lplpcid = lpcid ;
  187.  
  188.     // return to caller
  189.     return THING ;
  190. } // THNGIDENTIFY
  191.